<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends MY_Controller {

	public function __construct()
	{
		parent::__construct();
	}

	public function index()
	{
		redirect('login/autenticacao');
	}

	public function autenticacao()
	{
		$this->template->set_template('login');
		$this->template->render();
	}

	public function login_usuario()
	{
		$this->db
			->select("u.us_id, u.us_nome, u.us_login, u.us_senha, u.us_nome, u.us_status")
			->from("usuario u")
			->where("u.us_login = '".$this->input->post('usuario_login')."'")
			->where("u.us_senha = '".md5($this->input->post('usuario_pass'))."'");

			$us = $this->db->get();

			if ($us->num_rows == 1)
			{
				// Usuario existe
				$us = $us->row();

				// Usuario Inativo
				if ($us->us_status == 0)
				{
					$this->session->set_flashdata('erro', '<strong>Erro: </strong>usuário inativo.');
				}
				else 
				{
					// Passou na validacao
					$_SESSION['usuario'] = $us;
					redirect('painel', 'refresh');
				}
			}
			else
			{
				$this->session->set_flashdata('erro', '<strong>Erro: </strong>usuário ou senha inválidos.');
			}

		redirect('login/autenticacao');
	}

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */